package nodes;

import compiler.Compiler;
import compiler.SymbolTable;

import descriptors.AbstractDescr;
import descriptors.ConstDescr;

public class PrintNode extends StatementNode {

	private ExpressionNode expression;
	
	public PrintNode(ExpressionNode expression,int line, int column){
		super(line,column);
		this.expression=expression;
	}
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public AbstractDescr compile(
			SymbolTable symbolTable, Compiler compiler) {
		AbstractDescr descr=expression.compile(symbolTable, compiler);
		if (descr instanceof ConstDescr) compiler.write("PUSHI, "+ ((ConstDescr)descr).value());
		compiler.write("PRINT");
		return null;
	}

	@Override
	public void print() {
		trace("PrintNode");
		expression.print();
		unindent();
	}

}
